{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2024-02-20T06:50:12.653247Z",
     "start_time": "2024-02-20T06:50:12.651127Z"
    }
   },
   "outputs": [],
   "source": [
    "# 内置数据类型\n",
    "# list列表\n",
    "list1 = [1,2,3,4,5]\n",
    "list2 = ['aa','bb','cc','dd']\n",
    "list3 = [123, 'abc']\n",
    "list4 = [[1,'a'],[2,'b']]"
   ]
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['red', 'blue', 'green']\n",
      "<class 'list'>\n"
     ]
    }
   ],
   "source": [
    "colors = [\"red\",\"blue\",\"green\"]\n",
    "print(colors)\n",
    "print(type(colors))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:35:27.225280Z",
     "start_time": "2024-02-20T08:35:27.220489Z"
    }
   },
   "id": "e25169b15669a42e",
   "execution_count": 2
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "['r', 'e', 'd']"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list('red')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:36:22.393940Z",
     "start_time": "2024-02-20T08:36:22.390685Z"
    }
   },
   "id": "2682c412a12dcfa",
   "execution_count": 3
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6, 7, 8, 9]\n"
     ]
    }
   ],
   "source": [
    "#列表推导式\n",
    "print([x for x in range(1,10)])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:40:29.205765Z",
     "start_time": "2024-02-20T08:40:29.199958Z"
    }
   },
   "id": "6a01b63b0aacd30c",
   "execution_count": 4
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "'a'"
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "listA = ['a','b','c','d']\n",
    "listA[0]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:46:41.569475Z",
     "start_time": "2024-02-20T08:46:41.566795Z"
    }
   },
   "id": "1b9b0abb58f24d9c",
   "execution_count": 22
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "'b'"
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "listA[1]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:46:42.235367Z",
     "start_time": "2024-02-20T08:46:42.219472Z"
    }
   },
   "id": "114849d313cb1278",
   "execution_count": 23
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "'c'"
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "listA[2]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:46:42.614245Z",
     "start_time": "2024-02-20T08:46:42.612045Z"
    }
   },
   "id": "19506624aedc2ef1",
   "execution_count": 24
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "'d'"
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "listA[-1]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:46:43.043654Z",
     "start_time": "2024-02-20T08:46:43.041385Z"
    }
   },
   "id": "a6b941708a1f3dfe",
   "execution_count": 25
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "'c'"
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "listB = ['a','b',['c','d']]\n",
    "listB[2][0]"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:46:43.466512Z",
     "start_time": "2024-02-20T08:46:43.463841Z"
    }
   },
   "id": "c502be44d75c6f7e",
   "execution_count": 26
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['b', 'c', 'd']\n"
     ]
    }
   ],
   "source": [
    "del listA[0]\n",
    "print(listA)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:46:44.254018Z",
     "start_time": "2024-02-20T08:46:44.250313Z"
    }
   },
   "id": "8fc1c7d83cc235b2",
   "execution_count": 27
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'listA' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[0;31mNameError\u001B[0m                                 Traceback (most recent call last)",
      "Cell \u001B[0;32mIn[29], line 2\u001B[0m\n\u001B[1;32m      1\u001B[0m \u001B[38;5;66;03m#删除listA\u001B[39;00m\n\u001B[0;32m----> 2\u001B[0m \u001B[38;5;28;01mdel\u001B[39;00m listA\n\u001B[1;32m      3\u001B[0m \u001B[38;5;28mprint\u001B[39m(listA)\n",
      "\u001B[0;31mNameError\u001B[0m: name 'listA' is not defined"
     ]
    }
   ],
   "source": [
    "#删除listA\n",
    "del listA\n",
    "print(listA)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:47:44.110298Z",
     "start_time": "2024-02-20T08:47:44.100333Z"
    }
   },
   "id": "f5a0ece5ae40902b",
   "execution_count": 29
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n"
     ]
    }
   ],
   "source": [
    "listC = [[1,2,3],[4,5,6],[7,8,9]]\n",
    "print(listC)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:48:44.019097Z",
     "start_time": "2024-02-20T08:48:44.014995Z"
    }
   },
   "id": "7f1d97f25e4420b9",
   "execution_count": 31
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'b', 'c', 'd', 'e', ['f', 'g']]\n"
     ]
    }
   ],
   "source": [
    "#list参加操作：添加元素\n",
    "listD = ['a','b','c','d','e', ['f','g']]\n",
    "print(listD)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:54:12.488029Z",
     "start_time": "2024-02-20T08:54:12.481983Z"
    }
   },
   "id": "2bb84b10cfa3c45",
   "execution_count": 36
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['first', 'a', 'b', 'c', 'd', 'e', ['f', 'g']]\n"
     ]
    }
   ],
   "source": [
    "listD.insert(0, \"first\")  # 指定索引位置插入元素\n",
    "print(listD)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:55:01.732615Z",
     "start_time": "2024-02-20T08:55:01.727186Z"
    }
   },
   "id": "eebdd027adfb11d9",
   "execution_count": 37
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['first', 'a', 'b', 'c', 'd', 'e', 'last', ['f', 'g']]\n"
     ]
    }
   ],
   "source": [
    "listD.insert(-1, \"last\")\n",
    "print(listD)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:56:31.109714Z",
     "start_time": "2024-02-20T08:56:31.101352Z"
    }
   },
   "id": "c382e29debd74cd7",
   "execution_count": 38
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['first', 'a', 'b', 'c', 'd', 'e', 'last', ['f', 'g'], 'last_one']\n"
     ]
    }
   ],
   "source": [
    "listD.append(\"last_one\")\n",
    "print(listD)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:57:10.750419Z",
     "start_time": "2024-02-20T08:57:10.743735Z"
    }
   },
   "id": "d6e716466255220f",
   "execution_count": 39
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['first', 'a', 'b', 'c', 'd', 'e', 'last', ['f', 'g'], 'last_one', 'a', 'b', 'c', 'd']\n"
     ]
    }
   ],
   "source": [
    "listD.extend(\"abcd\")  # 将元素展开成一个一个小元素插入到列表的后面\n",
    "print(listD)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T08:57:59.413716Z",
     "start_time": "2024-02-20T08:57:59.406907Z"
    }
   },
   "id": "64e30b1181000500",
   "execution_count": 40
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 5, 6]\n"
     ]
    }
   ],
   "source": [
    "# 列表修改\n",
    "listE = [1, 2, 3, 4, 5, 6]\n",
    "print(listE)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:23.978960Z",
     "start_time": "2024-02-20T09:20:23.974208Z"
    }
   },
   "id": "aeadeeb8a482051b",
   "execution_count": 102
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6, 5, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "listE.reverse()\n",
    "print(listE)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:24.668380Z",
     "start_time": "2024-02-20T09:20:24.664191Z"
    }
   },
   "id": "d50173f35bed4187",
   "execution_count": 103
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6, 4, 3, 2, 1]\n"
     ]
    }
   ],
   "source": [
    "listE.remove(5)\n",
    "print(listE)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:25.130650Z",
     "start_time": "2024-02-20T09:20:25.126180Z"
    }
   },
   "id": "5b95a44565ad94dd",
   "execution_count": 104
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "list is [4, 3, 2, 1]\n",
      "result is 6\n"
     ]
    }
   ],
   "source": [
    "result = listE.pop(0)\n",
    "print(f\"list is {listE}\")\n",
    "print(f\"result is {result}\")"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:25.600774Z",
     "start_time": "2024-02-20T09:20:25.596016Z"
    }
   },
   "id": "49577f4cf7f9e126",
   "execution_count": 105
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "4"
     },
     "execution_count": 106,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(listE)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:26.183717Z",
     "start_time": "2024-02-20T09:20:26.178853Z"
    }
   },
   "id": "298aae95800e5d07",
   "execution_count": 106
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 3, 2, 1, '888']\n"
     ]
    }
   ],
   "source": [
    "listE.append('888')\n",
    "print(listE)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:27.841069Z",
     "start_time": "2024-02-20T09:20:27.836177Z"
    }
   },
   "id": "5d090122aa166a25",
   "execution_count": 107
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "data": {
      "text/plain": "3"
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(listE[4])"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:29.674894Z",
     "start_time": "2024-02-20T09:20:29.669889Z"
    }
   },
   "id": "fb9012538f4194ef",
   "execution_count": 108
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n"
     ]
    }
   ],
   "source": [
    "print(listE.count(3))"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-20T09:20:56.747967Z",
     "start_time": "2024-02-20T09:20:56.741396Z"
    }
   },
   "id": "58ade6520b817675",
   "execution_count": 112
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 1, 'b', 2, 'c', 3]\n"
     ]
    }
   ],
   "source": [
    "listF = ['a', 1, 'b', 2, 'c', 'c', 3]\n",
    "listF.remove('c')\n",
    "print(listF)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-21T01:52:56.208979Z",
     "start_time": "2024-02-21T01:52:56.203236Z"
    }
   },
   "id": "d419a918a250e9a9",
   "execution_count": 115
  },
  {
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{1, 'a', 2, 'c', 'b', 3}\n"
     ]
    }
   ],
   "source": [
    "listF = ['a', 1, 'b', 2, 'c', 'c', 3]\n",
    "#将列表类型改成集合类型，集合类型是不可重复的特性\n",
    "listF = set(listF)\n",
    "print(listF)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2024-02-21T01:56:00.203191Z",
     "start_time": "2024-02-21T01:56:00.192875Z"
    }
   },
   "id": "690f39e537d6fec7",
   "execution_count": 116
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
